package com.zhaoyang.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author 赵扬
 * @time 2020/5/15 21:50
 */
public class DbUtil {

    private String dbUrl = "jdbc:mysql://localhost:3306/db_student_manager_web";
    private String dbUser = "root";
    private String dbPassword = "1234";
    private String jdbcName = "com.mysql.jdbc.Driver";
    private Connection connection = null;
    public Connection getConnection(){
        try {
            Class.forName(jdbcName);
            connection = DriverManager.getConnection(dbUrl,dbUser,dbPassword);
        } catch (Exception e) {
            System.out.println("----------------数据连接失败------------------");
            e.printStackTrace();
        }
        return connection;
    }
    public void closeCon(){
        if(connection != null)
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
    }
}
